﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace CoreEx.Common.Validation
{
    /// <summary>
    /// Represents a set of validation rules.
    /// </summary>
    /// <typeparam name="T">The target type that the validation rules applies to.</typeparam>
    public interface IValidationRules<T>
    {
        /// <summary>
        /// Adds a new validation rule.
        /// </summary>
        /// <param name="rule">The <see cref="Expression{TDelegate}"/> that contains the validating code.</param>
        /// <param name="message">The message to be used when a validation rule is broken.</param>
        void AddRule(Expression<Func<T, bool>> rule, string message);
        
        /// <summary>
        /// Gets all the <see cref="IValidationRule{T}"/> instances for the target type.
        /// </summary>
        /// <returns>An <see cref="IEnumerable{T}"/> that contains <see cref="IValidationRule{T}"/> instances.</returns>
        IEnumerable<IValidationRule<T>> GetRules();
        
        /// <summary>
        /// Gets all the <see cref="IValidationRule{T}"/> instances that applies to the target type and <paramref name="propertyName"/>.
        /// </summary>
        /// <param name="propertyName">The name of the property for which to retrieve the validation rules.</param>
        /// <returns>An <see cref="IEnumerable{T}"/> that contains <see cref="IValidationRule{T}"/> instances.</returns>
        IEnumerable<IValidationRule<T>> GetRules(string propertyName);
    }
}
